public with sharing class Aramex_Smartpaperbpm_nd{

    public static string url = null;
    public static string soapXML = null;
    Public Static String WebParam {get; set;}
    public static string stdemo {get; set;}
    public static string xml = null;
    Public static Boolean flag = true;
    
    public static void Initializevariables()
    {
        // The webservice url -  Pass in the endpoint to be used using the string url 
        //url = 'http://demo.smartpaperbpm.com/difc/soap_server/hellowsdl2.php';  
        //url = 'http://eyeegypt.smartappsegypt.com/msd/Aramex/soap_server/hellowsdl2.php';  
        url = 'http://eyeegypt.smartappsegypt.com/msd/Aramex/afza/soap_server/AramexIntegrationService2.php';  

        soapXML = '<?xml version="1.0" encoding="ISO-8859-1"?>';
        soapXML += '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:servicename">';
        soapXML += '<SOAP-ENV:Body>';
        soapXML += '<DoSomething xmlns="urn:servicename">';
        soapXML += '<sf-parameters xmlns="">';
        soapXML += WebParam.replace(' & ', ' &amp; ') + '</sf-parameters>';        
        soapXML += '</DoSomething>';
        soapXML += '</SOAP-ENV:Body>';
        soapXML += '</SOAP-ENV:Envelope>';
        
        
        System.debug('The Request XML => '+ soapXML);
    }
    
    public static void CheckAramexShipment()
    {    
        // Instantiate a new http object
        Http h = new Http();
              
        // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
        HttpRequest req = new HttpRequest();
        
        Initializevariables();
        
        req.setBody(soapXML);
        req.setEndpoint(url);
        req.setMethod('POST');
        req.setHeader('Content-length', '510' );
        req.setHeader('Content-Type', 'text/xml; charset=ISO-8859-1');  
        req.setHeader('SOAPAction','"http://demo.smartpaperbpm.com/difc/soap_server/hellowsdl1.php#DoSomething"');
        stdemo = '';
        if(flag)
        {    
            //Commented out By Mustafa Zaidi on 9th of July 2012...(because Amazon Webservice is down)
            /*
            HttpResponse res = h.send(req);
            xml = res.getBody();
            XmlStreamReader reader = res.getXmlStreamReader();
            
            stdemo = readXMLResponse(reader,'Pass');*/
            if(!Test.isRunningTest())
            {
                HttpResponse res = h.send(req);                
                xml = res.getBody();
                XmlStreamReader reader = res.getXmlStreamReader();
                
                stdemo = readXMLResponse(reader,'Pass');
                System.debug('The XML Response => '+ stdemo);
            }
        }
    }
    
    public static String readXMLResponse(XmlStreamReader reader, String sxmltag)
    {
        string retValue;
        // Read through the XML
        system.debug(reader.toString());
        while(reader.hasNext()) {if (reader.getEventType() == XmlTag.START_ELEMENT) {if (reader.getLocalName() == sxmltag) {reader.next(); if (reader.getEventType() == XmlTag.characters) {retValue = reader.getText();    }} }reader.next();} return retValue;
    } 
    
    // OMM 03/12/2013
    public static void prepareShipment()
    {}
    
    
    /*String temp = 'shipment::4529142251:::status::Record Created::::shipment::4529184936:::status::Record Created::::shipment::4529142250:::status::Not Exists';
for (String token : temp.split('::::' , -2)){
    for (String subToken : token.split(':::' , -2)){
        system.debug('************************ Key : ' + subToken.split('::' , -2)[0] + ' , Value : ' +  + subToken.split('::' , -2)[1]); 
    }
}*/
//Barcode_Smartpaperbpm item = new Barcode_Smartpaperbpm();
/*Barcode_Smartpaperbpm.WebParam = 'AE|DXB|45796|216216|aadel@cloudconceptgroup.com|cloud123|v1.0' ;
Barcode_Smartpaperbpm.GenerateBarcode();
for (String token : Barcode_Smartpaperbpm.stdemo.split('::::' , -2)){
    system.debug(
        token.split(':::' , -2)[0].split('::' , -2)[0] + ' Number : ' + token.split(':::' , -2)[0].split('::' , -2)[1] +
        token.split(':::' , -2)[1].split('::' , -2)[0] + ' Status : ' + token.split(':::' , -2)[1].split('::' , -2)[1]
                
                );
}*/
//PDF417
}